<?php

/**
 * Tags Model
 *
 */
class Application_Model_Tags
{
    const DB_TABLE='tags';
    const RESOURCE_NAME='tags';
    
    protected $_data;
    
    public function __construct($tag=null)
    {
        if (!empty($tag) && (is_array($tag) || (is_object($tag) && ($tag instanceof Zend_Db_Table_Row))))
        {
            $this->_init($tag);
        } else 
        {
            $this->_init(array(
                'id' => 0,
                'tag' => '',
                'nid' => 0
            ));
        } 
    }
    
    /**
     * Magic function
     *
     * @param string $var
     */
    public function __get($var)
    {
        return $this->_getData($var);
    }
    
    /**
     * Magic function
     *
     * @param string $var
     * @param mixed $val
     */
    public function __set($var,$val)
    {
        $this->_setData($var,$val);
    }
    
    /**
     * Magic function
     *
     * @param string $var
     */
    public function __unset($var)
    {
        if (array_key_exists($var,$this->_data))
        {
            unset($this->_data[$var]);
        }
    }
    
    /**
     * Magic function
     *
     * @param string $var
     * @return bool
     */
    public function __isset($var)
    {
        return array_key_exists($var,$this->_data);
    }
    
    /**
     * Magic function
     *
     * @return string
     */
    public function __toString()
    {
        return (string) $this->tag;
    }
    
    /**
     * Initializes node
     *
     * @param mixed $user
     */
    protected function _init($tag)
    {
        foreach ($tag as $var=>$val)
        {
            $this->_setData($var,$val);
        }
    }
    
    /**
     * Gets variable value
     *
     * @param string $var
     * @return mixed
     */
    protected function _getData($var)
    {
        $method='_getValue'.ucwords($var);
        
        if (method_exists($this,$method))
        {
            return $this->{$method}();
        }
        
        return null;
    }
    
    /**
     * Sets variable value
     *
     * @param string $var
     * @param mixed $val
     */
    protected function _setData($var,$val)
    {
        $method='_setValue'.ucwords($var);
        
        if (method_exists($this,$method))
        {
            $this->{$method}($val);
        }
    }

    /**
     * Returns tag ID
     *
     * @return int
     */
    protected function _getValueId()
    {
        return (int) $this->_data['id'];
    }
    
    /**
     * Returns tag
     *
     * @return string
     */
    protected function _getValueTag()
    {
        return (string) $this->_data['tag'];
    }
    
    /**
     * Returns tag node ID
     *
     * @return int
     */
    protected function _getValueNid()
    {
        return (int) $this->_data['nid'];
    }
    
    /**
     * Returns tag node URL alias
     *
     * @return string
     */
    protected function _getValueUrl_alias()
    {
        return (int) $this->_data['url_alias'];
    }
    
    /**
     * Returns tag node language
     *
     * @return string
     */
    protected function _getValueLanguage()
    {
        return (int) $this->_data['language'];
    }
    
     /* Sets tag ID
     *
     * @param int $val
     */
    protected function _setValueId($val)
    {
        $this->_data['id']=(int) $val;
    }
    
     /* Sets tag
     *
     * @param string $val
     */
    protected function _setValueTag($val)
    {
        $this->_data['tag']=(string) $val;
    }
    
    /* Sets tag node ID
     *
     * @param int $val
     */
    protected function _setValueNid($val)
    {
        $this->_data['nid']=(int) $val;
    }
    
    /* Sets tag node URL alias
     *
     * @param string $val
     */
    protected function _setValueUrl_alias($val)
    {
        $this->_data['url_alias']=(string) $val;
    }
    
    /* Sets tag node language
     *
     * @param string $val
     */
    protected function _setValueLanguage($val)
    {
        $this->_data['language']=(string) $val;
    }
    
     /**
     * Returns an array with tag data
     *
     * @return array
     */
    public function toArray()
    {
        return $this->_data;
    }
}

